home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / disney / rabbitRivalry / ents / Entity.as next >
Encoding:
Text File  |  2009-06-09  |  7.1 KB  |  296 lines

  1. class disney.rabbitRivalry.ents.Entity extends smashing.keithm.Renderable
  2. {
  3.    var startSpin;
  4.    var startVelocity;
  5.    var owner;
  6.    var startGravity;
  7.    var doRemove;
  8.    var velocity;
  9.    var gravityVector;
  10.    var rotation;
  11.    var spin;
  12.    var isSpinning;
  13.    var __animation;
  14.    var isAlive;
  15.    var nextX;
  16.    var hdReg;
  17.    var hdWidth;
  18.    var nextY;
  19.    var hdHeight;
  20.    var x;
  21.    var y;
  22.    var nextZ;
  23.    var z;
  24.    var mc;
  25.    var __isAnimating;
  26.    var specialDepth;
  27.    var HAS_SPECIAL_DEPTH = false;
  28.    var __3D_SCALE = true;
  29.    var __IDLE_ANIMATION = "idle";
  30.    var __DEATH_ANIMATION = "die";
  31.    var __MAX_VELOCITY = 800;
  32.    var __USES_VELOCITY = true;
  33.    function Entity(t_data)
  34.    {
  35.       super(t_data);
  36.    }
  37.    function init(t_data)
  38.    {
  39.       if(t_data.spin != undefined)
  40.       {
  41.          this.startSpin = t_data.spin;
  42.       }
  43.       else
  44.       {
  45.          this.startSpin = 0;
  46.       }
  47.       if(t_data.vel != undefined)
  48.       {
  49.          this.startVelocity = t_data.vel;
  50.       }
  51.       else
  52.       {
  53.          this.startVelocity = new smashing.Point3D(0,0,0);
  54.       }
  55.       if(this.owner.gravity != undefined)
  56.       {
  57.          this.startGravity = this.owner.gravity;
  58.       }
  59.       else
  60.       {
  61.          this.startGravity = new smashing.Point3D(0,0,0);
  62.       }
  63.       this.doRemove = false;
  64.       super.init(t_data);
  65.    }
  66.    function reset()
  67.    {
  68.       this.velocity = this.startVelocity.copy();
  69.       this.gravityVector = this.startGravity.copy();
  70.       this.rotation = 0;
  71.       this.spin = this.startSpin;
  72.       if(this.startSpin == 0)
  73.       {
  74.          this.isSpinning = false;
  75.       }
  76.       else
  77.       {
  78.          this.isSpinning = true;
  79.       }
  80.       super.reset();
  81.       this.__animation = this.__IDLE_ANIMATION;
  82.    }
  83.    function takeDamage(power)
  84.    {
  85.       this.startDie();
  86.    }
  87.    function startDie()
  88.    {
  89.       this.kill();
  90.       this.animate(this.__DEATH_ANIMATION);
  91.       if(this.__USES_VELOCITY)
  92.       {
  93.          this.velocity.x = this.velocity.y = 0;
  94.       }
  95.    }
  96.    function endDie()
  97.    {
  98.    }
  99.    function onErase()
  100.    {
  101.       super.onErase();
  102.    }
  103.    function updateDraw(camera)
  104.    {
  105.       if(this.doRemove || !this.isAlive)
  106.       {
  107.          return undefined;
  108.       }
  109.       super.updateDraw(camera);
  110.    }
  111.    function runHD(t_target, dt)
  112.    {
  113.       if(!(this.isAlive && t_target.isAlive))
  114.       {
  115.          return false;
  116.       }
  117.       if(Math.abs(this.nextX + this.hdReg.x - (t_target.nextX + t_target.hdReg.x)) < this.hdWidth + t_target.hdWidth)
  118.       {
  119.          if(Math.abs(this.nextY + this.hdReg.y - (t_target.nextY + t_target.hdReg.y)) < this.hdHeight + t_target.hdHeight)
  120.          {
  121.             return true;
  122.          }
  123.       }
  124.       return false;
  125.    }
  126.    function hitReact(t_source)
  127.    {
  128.    }
  129.    function onDraw(t_newmc)
  130.    {
  131.       super.onDraw(t_newmc);
  132.       this.animate(this.__IDLE_ANIMATION);
  133.    }
  134.    function update(dt)
  135.    {
  136.       this.updateAnim();
  137.       if(this.__USES_VELOCITY)
  138.       {
  139.          this.nextX = this.x + this.velocity.x * dt;
  140.          this.nextY = this.y + this.velocity.y * dt;
  141.          this.nextZ = this.z + this.velocity.z * dt;
  142.       }
  143.    }
  144.    function move(dt)
  145.    {
  146.       if(this.__USES_VELOCITY)
  147.       {
  148.          this.x += this.velocity.x * dt;
  149.          this.y += this.velocity.y * dt;
  150.          this.z += this.velocity.z * dt;
  151.       }
  152.    }
  153.    function render(camera, dt)
  154.    {
  155.       super.render(camera,dt);
  156.    }
  157.    function moveAndRender(camera, dt)
  158.    {
  159.       if(this.__USES_VELOCITY)
  160.       {
  161.          this.nextX = this.x += this.velocity.x * dt;
  162.          this.nextY = this.y += this.velocity.y * dt;
  163.          this.nextZ = this.z += this.velocity.z * dt;
  164.       }
  165.       this.render(camera,dt);
  166.    }
  167.    function updateMoveAndRender(camera, dt)
  168.    {
  169.       this.updateAnim();
  170.       if(this.__USES_VELOCITY)
  171.       {
  172.          this.nextX = this.x += this.velocity.x * dt;
  173.          this.nextY = this.y += this.velocity.y * dt;
  174.          this.nextZ = this.z += this.velocity.z * dt;
  175.       }
  176.       this.render(camera,dt);
  177.    }
  178.    function animate(frame)
  179.    {
  180.       if(frame != undefined)
  181.       {
  182.          this.__animation = frame;
  183.       }
  184.       this.mc.gotoAndStop(this.__animation);
  185.       if(this.__animation == this.__IDLE_ANIMATION)
  186.       {
  187.          this.__isAnimating = false;
  188.       }
  189.       else
  190.       {
  191.          this.__isAnimating = true;
  192.       }
  193.    }
  194.    function updateAnim()
  195.    {
  196.       if(this.__isAnimating)
  197.       {
  198.          if(this.mc.anim._currentFrame == this.mc.anim._totalFrames)
  199.          {
  200.             if(this.__animation == this.__DEATH_ANIMATION)
  201.             {
  202.                this.endDie();
  203.             }
  204.             else
  205.             {
  206.                this.animate(this.__IDLE_ANIMATION);
  207.             }
  208.          }
  209.       }
  210.    }
  211.    function freezeAnimation()
  212.    {
  213.       this.mc.anim.stop();
  214.    }
  215.    function unfreezeAnimation()
  216.    {
  217.       if(this.__isAnimating)
  218.       {
  219.          this.mc.anim.play();
  220.       }
  221.       else
  222.       {
  223.          this.animate();
  224.       }
  225.    }
  226.    function replaceVelocity(t_vector)
  227.    {
  228.       this.velocity = t_vector.copy();
  229.    }
  230.    function inputVelocity(t_vector)
  231.    {
  232.       this.velocity.x += t_vector.x;
  233.       this.velocity.y += t_vector.y;
  234.       this.velocity.z += t_vector.z;
  235.    }
  236.    function addVelocity(t_vector, dt, maxVelocity, xMult, yMult, zMult)
  237.    {
  238.       this.velocity.x += t_vector.x * dt;
  239.       this.velocity.y += t_vector.y * dt;
  240.       this.velocity.z += t_vector.z * dt;
  241.    }
  242.    function getIntersect_line_line(t_lineStart, t_lineEnd, dt)
  243.    {
  244.       var _loc4_ = undefined;
  245.       var _loc3_ = undefined;
  246.       var _loc7_ = undefined;
  247.       var _loc6_ = undefined;
  248.       var _loc5_ = undefined;
  249.       if(this.velocity.x != 0)
  250.       {
  251.          _loc4_ = this.velocity.y / this.velocity.x;
  252.       }
  253.       else
  254.       {
  255.          _loc4_ = Infinity;
  256.       }
  257.       if(t_lineEnd.x - t_lineStart.x != 0)
  258.       {
  259.          _loc3_ = (t_lineEnd.y - t_lineStart.y) / (t_lineEnd.x - t_lineStart.x);
  260.       }
  261.       else
  262.       {
  263.          _loc3_ = Infinity;
  264.       }
  265.       _loc7_ = t_lineStart.y - _loc4_ * t_lineStart.x;
  266.       _loc6_ = t_lineStart.y - _loc3_ * t_lineStart.x;
  267.       _loc5_ = 1 / (_loc4_ * -1 - _loc3_ * -1);
  268.       return new smashing.Point3D((-1 * _loc6_ - -1 * _loc7_) * _loc5_,(_loc3_ * _loc7_ - _loc4_ * _loc6_) * _loc5_);
  269.    }
  270.    function magnitudeToVector(t_magnitude, t_angle)
  271.    {
  272.       var _loc2_ = undefined;
  273.       var _loc1_ = undefined;
  274.       var _loc3_ = t_angle * 0.017453292519943295;
  275.       _loc2_ = t_magnitude * Math.cos(_loc3_);
  276.       _loc2_ = Math.round(_loc2_ * 100) / 100;
  277.       _loc1_ = t_magnitude * Math.sin(_loc3_);
  278.       _loc1_ = Math.round(_loc1_ * 100) / 100;
  279.       return new smashing.Point3D(_loc2_,_loc1_,0);
  280.    }
  281.    function getDrawType()
  282.    {
  283.       return this.HAS_SPECIAL_DEPTH != true ? this.DRAWTYPE : this.DRAWTYPE + "_" + this.specialDepth;
  284.    }
  285.    function getIsAnimating()
  286.    {
  287.       return this.__isAnimating;
  288.    }
  289.    function setHDRegistration()
  290.    {
  291.       this.hdReg = {};
  292.       this.hdReg.x = 0;
  293.       this.hdReg.y = 0;
  294.    }
  295. }
  296.